import request from '@/config/axios'
import {string} from "vue-types";

// 合同模版 VO
export interface ContractTemplateVO {
  id: number // 编号
  ruleGroupId: number // 分组id
  ruleGroupName: string // 分组名称
  name: string // 合同名称
  enabled: boolean // 是否启用
  fileUrl: string // 合同文件地址
  type: string // 合同类型
}
export interface SaveTemplateFromVo extends FileTempFormDesignerData{
  fileTempId?:number,
  formName?: string,
}
export interface FileTempFormDesignerData{
  id?:string,
  version?:string,
  option?:any,
  formConfig?:any
}

// 合同模版 API
export const ContractTemplateApi = {
  // 查询合同模版分页
  getContractTemplatePage: async (params: any) => {
    return await request.get({ url: `/law/contract-template/page`, params })
  },

  // 查询合同模版详情
  getContractTemplate: async (id: number) => {
    return await request.get({ url: `/law/contract-template/get?id=` + id })
  },

  // 新增合同模版
  createContractTemplate: async (data: ContractTemplateVO) => {
    return await request.post({ url: `/law/contract-template/create`, data })
  },

  // 修改合同模版
  updateContractTemplate: async (data: ContractTemplateVO) => {
    return await request.put({ url: `/law/contract-template/update`, data })
  },

  // 删除合同模版
  deleteContractTemplate: async (id: number) => {
    return await request.delete({ url: `/law/contract-template/delete?id=` + id })
  },

  // 导出合同模版 Excel
  exportContractTemplate: async (params) => {
    return await request.download({ url: `/law/contract-template/export-excel`, params })
  },

  saveTemplateFrom:async (data:SaveTemplateFromVo)=>{
    return await request.post({url:'/law/template-from/saveTemplateFrom',data})
  },
  loadTemplateFrom:async (formId:string)=>{
    return await request.get<FileTempFormDesignerData>({ url: '/law/template-from/loadTemplateFrom', params: { formId } })
  }
}

export const ContractTemplateType = [
  { value: 'indictment', label: '起诉状' },
  { value: 'defense', label: '答辩状' },
  { value: 'contract', label: '合同' },
]
